import 'package:mahjong/entity/MessageContext.dart';
import 'package:mahjong/entity/mahjong/LicensingCard.dart';
import 'package:mahjong/entity/mahjong/MahjongInfoEntity.dart';
import 'package:mahjong/notify/CurrentUserInfo.dart';
import 'package:provider/provider.dart';

import 'AbstractMessageHandler.dart';
import 'package:mahjong/const/MahjongConst.dart';

class MessageCardLicensing extends AbstractMessageHandler {
  void doMessage(MessageContext message) {
    var currentUser = Provider.of<CurrentUserInfo>(navigatorKey.currentContext,
        listen: false);

    var roomInfo = Provider.of<MahjongInfoEntity>(navigatorKey.currentContext,
        listen: false);
    roomInfo.userLicensingCard();
    if (message.userId != currentUser.userId) {
      diskPartUserProvider[message.userId].otherLicensing();
    } else {
      var roomProvider = Provider.of<MahjongInfoEntity>(
          navigatorKey.currentContext,
          listen: false);
      LicensingCard licensingCard = LicensingCard.formJSON(message.body);
      roomProvider.licensingCard = licensingCard.licensingCard;
      currentUser.currentLicensing(licensingCard);
    }
  }
}
